Rename cargo-compile to cargo-build
authorYehuda Katz <wycats@gmail.com>
Tue, 24 Jun 2014 02:09:12 +0000 (19:09 -0700)
committerYehuda Katz <wycats@gmail.com>
Tue, 24 Jun 2014 02:09:12 +0000 (19:09 -0700)
Makefile
src/bin/cargo-build.rs [new file with mode: 0644]
src/bin/cargo-compile.rs [deleted file]
src/bin/cargo.rs
src/cargo/ops/cargo_rustc.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_git_deps.rs
tests/test_cargo_compile_path_deps.rs

index bededdd1d4be6b85df28587035b331455e8c547a..057a5e7a70452b28f18707fe116ed282e69d39c8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ DESTDIR ?= /usr/local
 
 # Link flags to pull in dependencies
 BINS = cargo \
-            cargo-compile \
+            cargo-build \
             cargo-read-manifest \
             cargo-rustc \
             cargo-verify-project \
diff --git a/src/bin/cargo-build.rs b/src/bin/cargo-build.rs
new file mode 100644 (file)
index 0000000..8a0f065
--- /dev/null
@@ -0,0 +1,54 @@
+#![crate_id="cargo-build"]
+#![feature(phase)]
+
+extern crate cargo;
+
+#[phase(plugin, link)]
+extern crate hammer;
+
+#[phase(plugin, link)]
+extern crate log;
+
+extern crate serialize;
+
+use std::os;
+use cargo::{execute_main_without_stdin};
+use cargo::ops;
+use cargo::core::MultiShell;
+use cargo::util::{CliResult, CliError};
+use cargo::util::important_paths::find_project;
+
+#[deriving(PartialEq,Clone,Decodable,Encodable)]
+pub struct Options {
+    manifest_path: Option<String>,
+    update_remotes: bool
+}
+
+hammer_config!(Options "Build the current project", |c| {
+    c.short("update_remotes", 'u')
+})
+
+fn main() {
+    execute_main_without_stdin(execute);
+}
+
+fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
+    debug!("executing; cmd=cargo-compile; args={}", os::args());
+
+    let root = match options.manifest_path {
+        Some(path) => Path::new(path),
+        None => try!(find_project(os::getcwd(), "Cargo.toml")
+                    .map(|path| path.join("Cargo.toml"))
+                    .map_err(|_| {
+                        CliError::new("Could not find Cargo.toml in this \
+                                       directory or any parent directory",
+                                      102)
+                    }))
+    };
+
+    let update = options.update_remotes;
+
+    ops::compile(&root, update, shell).map(|_| None).map_err(|err| {
+        CliError::from_boxed(err, 101)
+    })
+}
diff --git a/src/bin/cargo-compile.rs b/src/bin/cargo-compile.rs
deleted file mode 100644 (file)
index c097f6f..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#![crate_id="cargo-compile"]
-#![feature(phase)]
-
-extern crate cargo;
-
-#[phase(plugin, link)]
-extern crate hammer;
-
-#[phase(plugin, link)]
-extern crate log;
-
-extern crate serialize;
-
-use std::os;
-use cargo::{execute_main_without_stdin};
-use cargo::ops;
-use cargo::core::MultiShell;
-use cargo::util::{CliResult, CliError};
-use cargo::util::important_paths::find_project;
-
-#[deriving(PartialEq,Clone,Decodable,Encodable)]
-pub struct Options {
-    manifest_path: Option<String>,
-    update_remotes: bool
-}
-
-hammer_config!(Options "Compile the current project", |c| {
-    c.short("update_remotes", 'u')
-})
-
-fn main() {
-    execute_main_without_stdin(execute);
-}
-
-fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
-    debug!("executing; cmd=cargo-compile; args={}", os::args());
-
-    let root = match options.manifest_path {
-        Some(path) => Path::new(path),
-        None => try!(find_project(os::getcwd(), "Cargo.toml")
-                    .map(|path| path.join("Cargo.toml"))
-                    .map_err(|_| {
-                        CliError::new("Could not find Cargo.toml in this \
-                                       directory or any parent directory",
-                                      102)
-                    }))
-    };
-
-    let update = options.update_remotes;
-
-    ops::compile(&root, update, shell).map(|_| None).map_err(|err| {
-        CliError::from_boxed(err, 101)
-    })
-}
index 0508d556a230ddec5530961d12ef64114fd976d6..d8427326e7a038063b431dbac5f4a37abf837621 100644 (file)
@@ -32,10 +32,7 @@ struct ProjectLocation {
 fn execute() {
     debug!("executing; cmd=cargo; args={}", os::args());
 
-    let (cmd, args) = match process(os::args()) {
-        Ok((cmd, args)) => (cmd, args),
-        Err(err) => return handle_error(err, &mut shell(false))
-    };
+    let (cmd, args) = process(os::args());
 
     match cmd.as_slice() {
         "config-for-key" => {
@@ -52,7 +49,7 @@ fn execute() {
         },
         "--help" | "-h" | "help" | "-?" => {
             println!("Commands:");
-            println!("  compile          # compile the current project\n");
+            println!("  build          # compile the current project\n");
 
             let (_, options) = hammer::usage::<GlobalFlags>(false);
             println!("Options (for all commands):\n\n{}", options);
@@ -76,14 +73,11 @@ fn execute() {
     }
 }
 
-fn process(args: Vec<String>) -> CliResult<(String, Vec<String>)> {
-    let args: Vec<String> = Vec::from_slice(args.tail());
-    let head = try!(args.iter().nth(0).require(|| {
-        human("No subcommand found")
-    }).map_err(|err| CliError::from_boxed(err, 1))).to_str();
-    let tail = Vec::from_slice(args.tail());
+fn process(args: Vec<String>) -> (String, Vec<String>) {
+    let mut args = Vec::from_slice(args.tail());
+    let head = args.shift().unwrap_or("--help".to_str());
 
-    Ok((head, tail))
+    (head, args)
 }
 
 #[deriving(Encodable)]
index b28984080f490ad29dafab3095cdc5d463e286d0..3357ff886c9daf3fde9cd512bb632a253a5ff7da 100644 (file)
@@ -3,7 +3,7 @@ use std::io;
 use std::io::{File, IoError};
 use std::str;
 
-use core::{MultiShell, Package, PackageSet, Target};
+use core::{Package, PackageSet, Target};
 use util;
 use util::{CargoResult, ChainError, ProcessBuilder, internal, human, CargoError};
 use util::{Config};
index 4e7cb58e8a76837166fd3f8a4a7a2e101f746ec9..28a7d0225ed5ea35bd0625cda6b06125440a8a71 100644 (file)
@@ -30,7 +30,7 @@ test!(cargo_compile_simple {
         .file("Cargo.toml", basic_bin_manifest("foo").as_slice())
         .file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice());
 
-    assert_that(p.cargo_process("cargo-compile"), execs());
+    assert_that(p.cargo_process("cargo-build"), execs());
     assert_that(&p.root().join("target/foo"), existing_file());
 
     let target = p.root().join("target");
@@ -44,7 +44,7 @@ test!(cargo_compile_with_invalid_manifest {
     let p = project("foo")
         .file("Cargo.toml", "");
 
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
         execs()
         .with_status(101)
         .with_stderr("Cargo.toml is not a valid manifest\n\n\
@@ -58,7 +58,7 @@ test!(cargo_compile_with_invalid_manifest2 {
             foo = bar
         ");
 
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
         execs()
         .with_status(101)
         .with_stderr("could not parse input TOML\n\
@@ -68,7 +68,7 @@ test!(cargo_compile_with_invalid_manifest2 {
 test!(cargo_compile_without_manifest {
     let p = project("foo");
 
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
         execs()
         .with_status(102)
         .with_stderr("Could not find Cargo.toml in this directory or any \
@@ -82,7 +82,7 @@ test!(cargo_compile_with_invalid_code {
 
     let target = realpath(&p.root().join("target")).assert();
 
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
         execs()
         .with_status(101)
         .with_stderr(format!("\
@@ -101,7 +101,7 @@ test!(cargo_compile_with_warnings_in_the_root_package {
         .file("Cargo.toml", basic_bin_manifest("foo").as_slice())
         .file("src/foo.rs", "fn main() {} fn dead() {}");
 
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
         execs()
         .with_stderr("\
 src/foo.rs:1:14: 1:26 warning: code is never used: `dead`, #[warn(dead_code)] \
@@ -158,7 +158,7 @@ test!(cargo_compile_with_warnings_in_a_dep_package {
     let bar = realpath(&p.root().join("bar")).assert();
     let main = realpath(&p.root()).assert();
 
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
         execs()
         .with_stdout(format!("{} bar v0.5.0 (file:{})\n\
                               {} foo v0.5.0 (file:{})\n",
@@ -238,7 +238,7 @@ test!(cargo_compile_with_nested_deps_shorthand {
             }
         "#);
 
-    p.cargo_process("cargo-compile")
+    p.cargo_process("cargo-build")
         .exec_with_output()
         .assert();
 
@@ -314,7 +314,7 @@ test!(cargo_compile_with_nested_deps_longhand {
             }
         "#);
 
-    assert_that(p.cargo_process("cargo-compile"), execs());
+    assert_that(p.cargo_process("cargo-build"), execs());
 
     assert_that(&p.root().join("target/foo"), existing_file());
 
@@ -340,7 +340,7 @@ test!(custom_build {
         .file("src/foo.rs", r#"
             fn main() { println!("Hello!"); }
         "#);
-    assert_that(build.cargo_process("cargo-compile"),
+    assert_that(build.cargo_process("cargo-build"),
                 execs().with_status(0));
 
 
@@ -359,7 +359,7 @@ test!(custom_build {
         .file("src/foo.rs", r#"
             fn main() {}
         "#);
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0)
                        .with_stdout(format!("   Compiling foo v0.5.0 (file:{})\n",
                                             p.root().display()))
@@ -381,7 +381,7 @@ test!(custom_build_failure {
         .file("src/foo.rs", r#"
             fn main() { fail!("nope") }
         "#);
-    assert_that(build.cargo_process("cargo-compile"), execs().with_status(0));
+    assert_that(build.cargo_process("cargo-build"), execs().with_status(0));
 
 
     let mut p = project("foo");
@@ -399,7 +399,7 @@ test!(custom_build_failure {
         .file("src/foo.rs", r#"
             fn main() {}
         "#);
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(101).with_stderr(format!("\
 Could not execute process `{}` (status=101)
 --- stderr
@@ -430,7 +430,7 @@ test!(custom_build_env_vars {
         "#,
         p.root().join("target").display(),
         p.root().join("target/deps").display()));
-    assert_that(build.cargo_process("cargo-compile"), execs().with_status(0));
+    assert_that(build.cargo_process("cargo-build"), execs().with_status(0));
 
 
     p = p
@@ -447,7 +447,7 @@ test!(custom_build_env_vars {
         .file("src/foo.rs", r#"
             fn main() {}
         "#);
-    assert_that(p.cargo_process("cargo-compile"), execs().with_status(0));
+    assert_that(p.cargo_process("cargo-build"), execs().with_status(0));
 })
 
 test!(custom_build_in_dependency {
@@ -473,7 +473,7 @@ test!(custom_build_in_dependency {
         "#,
         p.root().join("target/deps").display(),
         p.root().join("target/deps").display()));
-    assert_that(build.cargo_process("cargo-compile"), execs().with_status(0));
+    assert_that(build.cargo_process("cargo-build"), execs().with_status(0));
 
 
     p = p
@@ -507,7 +507,7 @@ test!(custom_build_in_dependency {
         .file("bar/src/bar.rs", r#"
             pub fn bar() {}
         "#);
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0));
 })
 
@@ -529,7 +529,7 @@ test!(many_crate_types {
         .file("src/foo.rs", r#"
             pub fn foo() {}
         "#);
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0));
 
     let files = fs::readdir(&p.root().join("target")).assert();
index a5ae216874ed6f3ca4237a9760680ca0db564488..aad1c3ddf857c4ef38da929e5b8120e7680b3f4f 100644 (file)
@@ -84,7 +84,7 @@ test!(cargo_compile_simple_git_dep {
     let root = project.root();
     let git_root = git_project.root();
 
-    assert_that(project.cargo_process("cargo-compile"),
+    assert_that(project.cargo_process("cargo-build"),
         execs()
         .with_stdout(format!("{} git repository `file:{}`\n\
                               {} dep1 v0.5.0 (file:{})\n\
@@ -165,7 +165,7 @@ test!(cargo_compile_with_nested_paths {
         .file("src/parent.rs",
               main_file(r#""{}", dep1::hello()"#, ["dep1"]).as_slice());
 
-    p.cargo_process("cargo-compile")
+    p.cargo_process("cargo-build")
         .exec_with_output()
         .assert();
 
@@ -215,7 +215,7 @@ test!(recompilation {
               main_file(r#""{}", bar::bar()"#, ["bar"]).as_slice());
 
     // First time around we should compile both foo and bar
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_stdout(format!("{} git repository `file:{}`\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
@@ -224,7 +224,7 @@ test!(recompilation {
                                             COMPILING, p.root().display())));
 
     // Don't recompile the second time
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
                                             FRESH, git_project.root().display(),
@@ -235,13 +235,13 @@ test!(recompilation {
         pub fn bar() { println!("hello!"); }
     "#).assert();
 
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
                                             FRESH, git_project.root().display(),
                                             FRESH, p.root().display())));
 
-    assert_that(p.process("cargo-compile").arg("-u"),
+    assert_that(p.process("cargo-build").arg("-u"),
                 execs().with_stdout(format!("{} git repository `file:{}`\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
@@ -257,7 +257,7 @@ test!(recompilation {
     git_project.process("git").args(["commit", "-m", "test"]).exec_with_output()
                .assert();
 
-    assert_that(p.process("cargo-compile").arg("-u"),
+    assert_that(p.process("cargo-build").arg("-u"),
                 execs().with_stdout(format!("{} git repository `file:{}`\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
index f994e03719e0bcf5e5ed03a44ae1036e7077f726..412c8174861e9b08c1c240782468ad0801d4e07f 100644 (file)
@@ -72,7 +72,7 @@ test!(cargo_compile_with_nested_deps_shorthand {
             }
         "#);
 
-    p.cargo_process("cargo-compile")
+    p.cargo_process("cargo-build")
         .exec_with_output()
         .assert();
 
@@ -117,20 +117,20 @@ test!(no_rebuild_dependency {
             pub fn bar() {}
         "#);
     // First time around we should compile both foo and bar
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
                                             COMPILING, bar.display(),
                                             COMPILING, p.root().display())));
     // This time we shouldn't compile bar
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
                                             FRESH, bar.display(),
                                             FRESH, p.root().display())));
 
     p.build(); // rebuild the files (rewriting them in the process)
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
                                             COMPILING, bar.display(),
@@ -190,14 +190,14 @@ test!(deep_dependencies_trigger_rebuild {
         .file("baz/src/baz.rs", r#"
             pub fn baz() {}
         "#);
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
                                             COMPILING, baz.display(),
                                             COMPILING, bar.display(),
                                             COMPILING, p.root().display())));
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
@@ -213,7 +213,7 @@ test!(deep_dependencies_trigger_rebuild {
     File::create(&p.root().join("baz/src/baz.rs")).write_str(r#"
         pub fn baz() { println!("hello!"); }
     "#).assert();
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
@@ -226,7 +226,7 @@ test!(deep_dependencies_trigger_rebuild {
         extern crate baz;
         pub fn bar() { println!("hello!"); baz::baz(); }
     "#).assert();
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
@@ -289,14 +289,14 @@ test!(no_rebuild_two_deps {
         .file("baz/src/baz.rs", r#"
             pub fn baz() {}
         "#);
-    assert_that(p.cargo_process("cargo-compile"),
+    assert_that(p.cargo_process("cargo-build"),
                 execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",
                                             COMPILING, baz.display(),
                                             COMPILING, bar.display(),
                                             COMPILING, p.root().display())));
-    assert_that(p.process("cargo-compile"),
+    assert_that(p.process("cargo-build"),
                 execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
                                              {} bar v0.5.0 (file:{})\n\
                                              {} foo v0.5.0 (file:{})\n",